const App = getApp()

Page({
  data: {
    isHave: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  onLoad() {
    App.getUserId()
    this.getUserInfo()
    let params = {
      page: 1,
      pageSize: 10
    }

    App.HttpServiceNoToast.getCommentByUser(params).then(res => {
      console.log(res)
      this.setData({
        selfCommentList: res.data.data.selfCommentList,
        paginate: res.data.data.paginate,
        isHave: res.data.data.selfCommentList.length > 0
      })
    })
  },
  onReachBottom() {
    if (!this.data.paginate.hasNext) {
      return
    }
    let params = {
      page: this.data.paginate.next,
      pageSize: this.data.paginate.perPage,
    }
    App.HttpServiceNoToast.getCommentByUser(params).then(res => {
      console.log(res)
      this.setData({
        selfCommentList: res.data.data.selfCommentList,
        paginate: res.data.data.paginate
      })

      if (res.data.data.selfCommentList) {
        this.data.selfCommentList = [...this.data.selfCommentList, ...res.data.data.selfCommentList]
      }
      this.setData({
        selfCommentList: this.data.selfCommentList,
        paginate: res.data.data.paginate,
        isHave: this.data.selfCommentList.length > 0
      })

    })

  },


  bindgetuserinfo(detail) {
    console.log(detail)
    if (App.data.canIUse) {
      App.HttpService.bindgetuserinfo(detail, this.getUserInfo)
    } else {
      App.HttpService.getUserInfo()
    }
  },
  getUserInfo() {
    let userInfo = App.CacheService.getUserInfo()
    this.setData({
      userInfo: userInfo
    });
  },


  gotoSkin: function() {
    App.WxService.navigateTo("/pages/mine/skin/skin")
  },
  gotoFavorite: function() {
    App.WxService.navigateTo("/pages/mine/favorite/favorite")
  },

  navigaToActiveDetail(e) {

    App.WxService.navigateTo("/pages/goods/detail/detail", {
      goodsId: e.currentTarget.dataset.id
    })
  },

})